<template>
    <div class="my-oderPay background" :style="{height: `${screenHeight}px`}">
        <mt-loadmore
          ref="loadmore"
          v-if="listData.length>0"
          :bottom-method="loadBottom" 
          :bottomDistance="10"
          :autoFill="false"
          bottomDropText=""
          bottomLoadingText=""
          :bottom-all-loaded="allLoaded">
            <ul>
                <li class="my-oderPay-list" v-for="item in listData" :key="item.id">
                    <div class="my-oderPay-list-left">
                        <h5 v-if="item.registration">{{item.registration.title}}</h5>
                        <h5 v-else style="color:red">未获取到活动名称~</h5>
                        <div>{{item.payTime | formatHMS}}</div>
                    </div>
                    <div class="my-oderPay-list-right">￥<span>{{item.payMoney}}</span></div>
                </li>
                <span style="font-size:12px;color:#bbb;padding: 2px;" v-if="!allLoaded">上拉加载更多↑</span>
                <span style="font-size:12px;color:#bbb;padding: 2px;" v-if="allLoaded && listData.length >12">—— 你触及到我的底线啦~ ——</span>
            </ul>
        </mt-loadmore>
        <div v-else style="color:#ccc">还没有付款数据哦~</div>
    </div>
</template>

<script>
    import {getOderPayDate} from '../../api/request.js'
    import { setStore, getStore, formatHMS } from '../../assets/js/utils.js'
    import { Loadmore } from 'mint-ui';
    import wxjssdk from '../../assets/js/wxsdk'
    export default {
        name: "OderPay",
        data() {
            return {
                allLoaded:false,
                userId: '',
                pageNo: 1,
                listData: []
            }
        },
        computed: {
            screenHeight() {
                return window.innerHeight-40;
            }
        },
        created(){
            this.$store.commit('UPDATE_PAGE_TITLE', '付款记录');
            this.$store.commit('UPDATE_BACKSHOW', false);
            this.$store.commit('UPDATE_FOOTER', false);
            let userId = getStore('userId');
            let user = getStore('user');
            if(userId && user){
                this.userId = userId;
                this.loadBottom();
            }else{
                var fhUrl = window.location.href;
                setStore('fhUrl', fhUrl);
                this.$router.push('/wxLogin')
            }
        },
        mounted(){},
        methods: {
             loadBottom() {
                let that = this;
                getOderPayDate(this.userId,this.pageNo).then((res) => {
                    if (res.code == 1) {
                        that.pageNo++;
                        that.listData.push.apply(that.listData,res.data); 
                        if(res.data.length<10){
                            that.allLoaded = true; // 数据已全部获取完毕
                        }
                    }
                    that.$refs.loadmore.onBottomLoaded();
                }).catch(err => console.log(err)) 
            },
        },
        components:{
            "mt-loadmore":Loadmore
        },
        filters:{
            formatHMS:formatHMS
        }
    }
</script>

<style lang="scss" scoped>
    .my-oderPay {
        margin-top: 40px;
        padding: 10px;
        box-sizing: border-box;
        height: 100%;
        ul{
            border-radius: 20px;
        }
        &-list{
            box-sizing: border-box;
            border-bottom: 1px solid #ddd;
            width: 100%;
            background-color: #ffffff;
            padding:10px;
            text-align: left;
            overflow: auto;
            border-radius: 5px;
            &-left{
                float: left;
                div{
                    float: left;
                    color: #9c9c9c;
                    font-size: 12px;
                }
            }
            &-right{
                float: right;
                color: red;
                padding-top: 8px;
            }
        }
    }
</style>